package com.auto.finance.auth.collect.support.handles;

import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;

/**
 * @author tianye
 */
public class RequestMappingPathHandle extends AbstractRequestPathHandle {

    private static final Integer REQUEST_METHOD_LIMIT = 1;

    @Override
    protected String[] getPaths(Annotation annotation) {
        return ((RequestMapping) annotation).value();
    }

    @Override
    protected String[] getMethod(Annotation annotation) {
        RequestMapping anno = ((RequestMapping) annotation);
        List<String> list = new ArrayList<>();
        for (int i = 0; i < REQUEST_METHOD_LIMIT; i++) {
            list.add(anno.method()[i].name());
        }
        return list.toArray(new String[list.size()]);
    }

    @Override
    public boolean support(Annotation annotation) {
        return annotation instanceof RequestMapping;
    }
}
